pspsdkfandomcom-20200213-history
Basic Makefile
Introduction *Make is a powerful Unix tool allowing devs to automate the compiling/building process. What it does, is reading a file called Makefile, that contains all necessary instructions and rules to compile your project, and execute them. *Basically, imagine two file in the same folder; main.c, containing the source code of our homebrew and a file called Makefile. Assuming the Makefile does his job, what we want to be able to do is to call make (not makefile), that will compile our program according to the rules contained in the file Makefile. Write your first Makefile Let's start with a small project example (I assume you are already familiar with the code in main.c): *'main.c :' #include #include PSP_MODULE_INFO("Hello World", 0, 1, 0); int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main() { pspDebugScreenInit(); SetupCallbacks(); pspDebugScreenPrintf("Hello World"); sceKernelSleepThread(); return 0; } *'Makefile :' (the simplest possible) OBJS = main.o CFLAGS = -Wall -Wextra CXXFLAGS = $(CFLAGS) LIBS = EXTRA_TARGETS = EBOOT.PBP PSPSDK = $(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak Now let's explain a little more about this strange file ! OBJS = main.o This line tells psp-gcc (our compiler) which file needs to be compiled, in our case main.c. *'Note : '''don't forget to replace *.c (or *.cpp) by *.o ! I know it's weird, but not relevant for now. Example: if your project is composed of, say '''main.c', gfx.c and sound.c, your OBJS line will look like that: OBJS = main.o gfx.o sound.o Now let's give our compiler more information: CFLAGS = -Wall -Wextra CXXFLAGS = $(CFLAGS) These define flags. They modify the behavior of your compiler. '-Wall' (for "all warnings") for example, is a very common flag, that enables standard warnings. Warnings are sent by the compiler when your C code may contain errors. '-Wextra' enables more warnings. You can code without them, but I strongly advise their use, because they can be of a great help ! There are many useful flags, feel free to look into existing code and inspect Makefiles ! CXXFLAGS are also flags, except they are used in C++ only ! *'Note :' $(CFLAGS) is replaced by the contents of CFLAGS, $(...) can be a very useful syntax ! LIBS = This line defines what libraries will be used by our program. It's empty because we don't need them for this project, but you will later ! EXTRA_TARGETS = EBOOT.PBP PSPSDK = $(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak These lines are mandatory, but you don't need to understand what they do for now. Basically they define the name of you Eboot file, and retrieve build infos from another file called build.mak You can now save those two files and call make ! my_directory $ ls main.c Makefile my_directory $ make ... Wait for the compiler to finish, and a EBOOT.PBP file should appear ! Now turn on and connect your PSP, and transfer it ! The path should look like that: psp_root/PSP/GAME/MY_MAGICAL_HB/EBOOT.PBP Deconnect USB and your HB should appear in your game list ! Go further Makefiles are very useful and can save a lot of time for the programmer. This small tutorial showed a very basic use of them, don't hesitate to look for more advanced features ! Category:Makefile Category:build Category:make Category:Basics Category:Tutorials